<?php 
HeaderScripts::addScripts(array(
	'admin/spinner.js',
	'admin/spinnerField.js',
	'admin/multiSelect.js',
	'admin/itemSelector.js',
	'admin/fileUploadField.js'
));
HeaderScripts::addStyles(array(
	'admin/spinner.css',
	'admin/multiSelect.css',
	'admin/fileUploadField.css',
	'admin/form.css'
));
?>
<script type="text/javascript">
var citiesArr  = <?php echo CJSON::encode($cities)?>;
var excursions = <?php echo CJSON::encode($excursions)?>;
var hotelFeatures = <?php echo CJSON::encode($hotelFeatures)?>;
var roomFeatures  = <?php echo CJSON::encode($roomFeatures)?>;

Ext.namespace('Ext.cities');

var dateFieldCounter = 1;

Ext.onReady(function(){
	
	Ext.cities.data = citiesArr;
	
	var ds = new Ext.data.ArrayStore({
	        data: excursions,
	        fields: ['value','text'],
	        sortInfo: {
	            field: 'text',
	            direction: 'ASC'
	        }
	});
	
	var ds2 = new Ext.data.ArrayStore({
	        data: hotelFeatures,
	        fields: ['value','text'],
	        sortInfo: {
	            field: 'text',
	            direction: 'ASC'
	        }
	});
	
	var ds3 = new Ext.data.ArrayStore({
	        data: roomFeatures,
	        fields: ['value','text'],
	        sortInfo: {
	            field: 'text',
	            direction: 'ASC'
	        }
	});

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    var formhotelcreate = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        standardSubmit: true,
		fileUpload: true,
		url: '/admin/hotel/createhandler/',
        frame:true,
        title: 'Создать отель',
        bodyStyle:'padding:5px 5px 0',
        width: 600,

        items: [{
            xtype:'fieldset',
            title: 'Общая информация',
            collapsible: true,
            autoHeight:true,
            defaults: {width: 210},
			labelWidth: 130,
            defaultType: 'textfield',
            items :[{
                    fieldLabel: 'Название',
                    name: 'Hotel[title]',
                    allowBlank:false,
					blankText: 'Поле обязательно для заполнения'
			}, new Ext.form.ComboBox({
                    fieldLabel: 'Город',
                    hiddenName: 'Hotel[cityId]',
                    store: new Ext.data.ArrayStore({
                        fields: ['value', 'city'],
                        data : Ext.cities.data
                    }),
                    displayField: 'city',
					valueField: 'value',
                    typeAhead: true,
                    mode: 'local',
                    triggerAction: 'all',
                    emptyText: 'Выберите город',
                    selectOnFocus:true,
                    width: 200,
                    editable: false,
					allowBlank:false,
					blankText: 'Поле обязательно для заполнения'
			}),{
					fieldLabel: 'Адрес',
                	name: 'Hotel[address]',
					xtype:'textarea',
					height: 60
			},{
					xtype: 'spinnerfield',
					fieldLabel: 'Количество звезд',
					name: 'Hotel[stars]',
					minText: 'Минимальное допустимое значение: {0}',
					minValue: 0,
					maxValue: 5,
					allowDecimals: false,
					decimalPrecision: 1,
					incrementValue: 1,
					accelerate: true,
					value: 0
            },{
                fieldLabel: 'Валюта',
                name: 'Hotel[currency]'
			}]
        },{
            xtype:'fieldset',
            title: 'Экскурсии',
            collapsible: true,
            autoHeight:true,
			labelWidth: 130,
            defaults: {width: 420},
            defaultType: 'textfield',
            items :[{
					name: 'Hotel[availableTours]',
					id:'availableTours',
					fieldLabel: 'Наличие экскурсий',
					xtype:'checkbox',
					checked: true,
					inputValue: 1
			},{
            		xtype: 'itemselector',
            		name: 'Hotel2excursion',
            		fieldLabel: 'Экскурсии',
	        		imagePath: '/public/assets/extjs/resources/images/default/multiselect/',
	        		height: 200,
            		multiselects: [{
						dragGroup: 'toursDD',
						dropGroup: 'toursDD',
						width: 200,
                		height: 200,
                		cls: 'multiselectStr',
                		store: ds,
                		displayField: 'text',
                		valueField: 'value'
            		},{
						dragGroup: 'toursDD',
						dropGroup: 'toursDD',
						width: 200,
                		height: 200,
                		cls: 'multiselectStr',
                		store: [],
						tbar:[{
                    		text: 'очистить',
                    		handler:function(){
	                    		formhotelcreate.getForm().findField('Hotel2excursion').reset();
	                		}
                		}]
            		}]
        	}]
        },{
            xtype:'fieldset',
            title: 'Описание отеля',
            collapsible: true,
            autoHeight:true,
			labelWidth: 130,
            defaults: {width: 420},
            defaultType: 'textfield',
            items :[{
					name: 'Hotel[description]',
					id:'description',
					fieldLabel: 'Описание',
					xtype:'textarea',
					height: 100
			},{
                    fieldLabel: 'Номера',
                    name: 'Hotel[rooms]',
					xtype:'textarea',
					width: 420,
					height: 100
			},{
                fieldLabel: 'Трансфер',
                name: 'Hotel[transfer]',
				xtype:'textarea',
				width: 420,
				height: 100
			},{
            		xtype: 'itemselector',
            		name: 'Hotel2hotelFeatures',
            		fieldLabel: 'Фишки отеля',
	        		imagePath: '/public/assets/extjs/resources/images/default/multiselect/',
					valueField: 'value',
					height: 200,
            		multiselects: [{
            			width: 200,
                		height: 200,
                		cls: 'multiselectStr',
                		store: ds2,
                		displayField: 'text',
                		valueField: 'value',
						dragGroup: 'hotelDD',
						dropGroup: 'hotelDD'
            		},{
						dragGroup: 'hotelDD',
						dropGroup: 'hotelDD',
						valueField: 'value',
						width: 200,
                		height: 200,
                		cls: 'multiselectStr',
                		store: [],
						tbar:[{
                    		text: 'очистить',
                    		handler:function() {
	                    		formhotelcreate.getForm().findField('Hotel2hotelFeatures').reset();
	                		}
                		}]
            		}]
        	},{
            		xtype: 'itemselector',
            		name: 'Hotel2roomFeatures',
            		fieldLabel: 'Фишки номера',
	        		imagePath: '/public/assets/extjs/resources/images/default/multiselect/',
					valueField: 'value',
					height: 200,
            		multiselects: [{
                		dragGroup: 'roomDD',
						dropGroup: 'roomDD',
						width: 200,
                		height: 200,
                		cls: 'multiselectStr',
                		store: ds3,
                		displayField: 'text',
                		valueField: 'value'
            		},{
                		dragGroup: 'roomDD',
						dropGroup: 'roomDD',
						width: 200,
                		height: 200,
                		cls: 'multiselectStr',
						valueField: 'value',
                		store: [],
						tbar:[{
                    		text: 'очистить',
                    		handler:function(){
	                    		formhotelcreate.getForm().findField('Hotel2roomFeatures').reset();
	                		}
                		}]
            		}]
        	}]
        }<?php if ($imagesConfig['maxPhotos'] > 0) { ?>,{
			xtype: 'fieldset',
			title: 'Фотографии',
			collapsible: true,
			autoHeight: true,
			labelWidth: 130,
			defaults: {
				width: 420
			},
			defaultType: 'textfield',
			items: [<?php for($i = 1; $i <= $imagesConfig['maxPhotos']; $i++) {?>{
				xtype: 'fileuploadfield',
            	id: 'photoField<?php echo $i ?>',
            	emptyText: 'Выберите изображение',
            	fieldLabel: 'Фото #<?php echo $i ?>',
            	name: 'HotelPhoto[]',
            	buttonText: '',
				width: 250,
            	buttonCfg: {
                	iconCls: 'upload-icon'
            	}
			}<?php if ($imagesConfig['maxPhotos'] != $i) {?>,<?php } ?><?php } ?>]
		}<?php }?>],

        buttons: [{
            text: 'Сохранить',
			handler: function(b) {
				var fp = this.ownerCt.ownerCt,
					form = fp.getForm();
				if (form.isValid()) {
					b.disable();
					form.getEl().dom.action = '/admin/hotel/createhandler/';
					form.submit();
            	} else {
					formhotelcreate.form.markInvalid();
					Ext.MessageBox.alert('Ошибка!', 'Ошибка, информация неверная! Проверьте правильность заполнения полей!');
				}
			}
        },{
            text: 'Отменить',
            handler: function() {
            	location.href = '/admin/hotel/';
            }
        }]
    });

    formhotelcreate.render(Ext.get('hotelcreatediv'));
});
</script>
<div id="hotelcreatediv"></div>